﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CNVP.JShop.UI;
using CNVP.Framework;
using CNVP.Framework.Utils;

namespace CNVP.JShop.Web.Admin
{
    public partial class AdminRoleEdit : AdminPage
    {
        BLL.CNVP_AdminRole bll = new BLL.CNVP_AdminRole();
        Model.CNVP_AdminRole model = new Model.CNVP_AdminRole();
        public int id = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!BLL.BLLCheckAdmin.LoginOk(Page, 88)) return;//判断页面权限
            if (!string.IsNullOrEmpty(Request.QueryString["ID"]) && Public.IsNumber(Request.QueryString["ID"]))
            {
                id = Convert.ToInt32(Request.QueryString["ID"]);
            }
            if (!IsPostBack)
            {
                if (id > 0)
                {
                    lbTitle.Text = " > 修改";
                    DataInfo(id);
                }
                else
                {
                    lbTitle.Text = " > 添加";
                }
            }
        }

        public void DataInfo(int id)
        {
            model = bll.GetSingle_CNVP_AdminRoleById(id);
            if (model != null)
            {
                txtRoleName.Text = model.RoleName;
                rblIsLock.SelectedValue = model.IsLock.ToString();
            }
        }

        protected void btUp_Click(object sender, EventArgs e)
        {
            if (id > 0)
            {
                int rows = new BLL.CNVP_AdminRole().Update_CNVP_AdminRole(
                       new Model.CNVP_AdminRole()
                       {
                           ID=id,
                           RoleName = txtRoleName.Text.Trim(),
                           IsLock = byte.Parse(rblIsLock.SelectedValue)
                       }

               );
                if (rows == 1)
                {
                    BasePage.MessageBox("修改成功！", "AdminRoleList.aspx?Page=" + Request.QueryString["Page"] + "");
                }
                else
                { BasePage.MessageBoxGoHistory("修改失败！"); }
            }
            else
            {
                int rows = new BLL.CNVP_AdminRole().Add_CNVP_AdminRole(
                        new Model.CNVP_AdminRole()
                        {
                            RoleName = txtRoleName.Text.Trim(),
                            IsLock = byte.Parse(rblIsLock.SelectedValue)
                        }

                );
                if (rows == 1)
                {
                    BasePage.MessageBox("添加成功！","AdminRoleList.aspx");
                }
                else
                { BasePage.MessageBoxGoHistory("添加失败！"); }
            }
        }

    }
}